package servlet.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import servlet.bean.CourseBean;
import servlet.bean.TeacherBean;
import servlet.model.ServiceFactory;
import servlet.publicUtils.MyUtils;

public class CouAddServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		CourseBean couB = (CourseBean) MyUtils.getNewInstance(CourseBean.class);
		couB.setCou_num(MyUtils.obj2Integer(request.getParameter("counum")));
		couB.setCou_id(request.getParameter("couid"));
		couB.setCou_name(request.getParameter("couname"));
		int j=ServiceFactory.getUserInfoManagerServiceInstance().saveCouInfo(couB);
		
		
		
		if(j>0){
			List<CourseBean> lstCou=ServiceFactory.getUserInfoManagerServiceInstance().getCou();
			request.getSession().setAttribute("lstCou", lstCou);
			request.removeAttribute("couB");
			
			request.getRequestDispatcher("logined/teaCouInfo.jsp").forward(request, response);
		}else{
			request.getSession().setAttribute("pageErrorInfo", "用户信息添加失败");
			response.sendRedirect("logined/teaerror.jsp");
		}
		
	}

}
